package edu.hhu.analyse;

import polyfit.PolyFit;

import com.mathworks.toolbox.javabuilder.MWArray;
import com.mathworks.toolbox.javabuilder.MWClassID;
import com.mathworks.toolbox.javabuilder.MWNumericArray;

public class Analyse {
	public String  analyseMethod(double[] dbx, double[] dby, int m) {
		Object[] result = null;// 输出
		String res="";
		
		try {
			PolyFit myfunction = new PolyFit();
			
			// double[] dbx={1,2,3,4,5};
			// double[] dby={2,4,6,8,10};
			MWNumericArray x = new MWNumericArray(dbx, MWClassID.DOUBLE);
			MWNumericArray y = new MWNumericArray(dby, MWClassID.DOUBLE);
			result = myfunction.mypolyfit(1,x,y,m);
			MWNumericArray temp = (MWNumericArray)result[0];
					
			double[][] result1 = (double[][]) temp.toDoubleArray();
			for (int i = 0; i < result1.length; i++) {   //打印1
				for(int j=0;j<result1[i].length;j++){
					res=res+result1[i][j]+",";
					System.out.println(res);
				}
			}
			
			MWArray.disposeArray(dbx);
            MWArray.disposeArray(dby);
            MWArray.disposeArray(x);
            MWArray.disposeArray(y);
            MWArray.disposeArray(result);
           

		} catch (Exception e) {
			System.out.println("Exception: " + e.toString());
		}
		return res;
	}

}
